package org.sdp.pearproject.dto.request;

import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Getter;
import lombok.Setter;

import java.util.Date;

@Getter
@Setter
public class BaseRequest {
    @JsonProperty("query_options")
    @JSONField(name = "query_options")
    public transient JSONObject queryOptions;

    @JsonProperty("query_options_ori")
    @JSONField(name = "query_options_ori")
    public transient JSONObject queryOptionsOri;

    @JsonProperty("page_size")
    @JSONField(name = "page_size")
    public transient Integer pageSize;

    @JsonProperty("page_size_ori")
    @JSONField(name = "page_size_ori")
    public transient Integer pageSizeOri;

    @JsonProperty("page_no")
    @JSONField(name = "page_no")
    public transient Integer pageNo;

    @JsonProperty("page_no_ori")
    @JSONField(name = "page_no_ori")
    public transient Integer pageNoOri;

    @JsonProperty("page")
    @JSONField(name = "page")
    public transient Integer page;

    @JsonProperty("page_ori")
    @JSONField(name = "page_ori")
    public transient Integer pageOri;

    @JsonProperty("member_code_auth")
    @JSONField(name = "member_code_auth")
    private transient String memberCodeAuth;

    @JsonProperty("member_code_ori")
    @JSONField(name = "member_code_ori")
    private transient String memberCodeOri;

    @JsonProperty("organization_code")
    @JSONField(name = "organization_code")
    private transient String organizationCode;

    @JsonProperty("organization_code_auth")
    @JSONField(name = "organization_code_auth")
    private transient String organizationCodeAuth;

    @JsonProperty("organization_code_ori")
    @JSONField(name = "organization_code_ori")
    private transient String organizationCodeOri;

    @JsonProperty("device_id")
    @JSONField(name = "device_id")
    private transient String deviceId;

    @JsonProperty("client_timestamp")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @JSONField(format = "yyyy-MM-dd HH:mm:ss", name = "client_timestamp")
    private transient Date clientTimestamp;

    @JsonProperty("encrypt_password")
    @JSONField(name = "encrypt_password")
    private transient String encryptPassword;

    @JsonProperty("encrypt_iv")
    @JSONField(name = "encrypt_iv")
    private transient String encryptIv;

    public void checkParam() throws Exception {
    }

    public void assertNotNull(Object obj, String title) throws Exception {
        if (obj == null) {
            throw new Exception(title + " is null");
        }
    }
}
